/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
 var minimumDifference = function(nums, k) {
  nums.sort((a,b) => a-b)
  let ans = Number.MAX_SAFE_INTEGER
  const n = nums.length
  for(let i = 0; i+k-1 < n; i++){
    ans = Math.min(ans, nums[i+k-1]-nums[i])
  }
  return ans
};